import { dialogForm, DialogFormOptions } from "@/utils/dialogForm";
import ContractEdit from "../components/ContractEdit.vue";
import AgvTypeEdit from "../components/AgvTypeEdit.vue";

import { getListAllUser } from "@/api/modules/sys";
import { getCompanyList } from "@/api/modules/customer";
import { addOrder } from "@/api/modules/order";
import { getProjectListCodeAll } from "@/api/modules/project";

import { useDict } from "@/hooks/useDict";
import { useAddress } from "@/hooks/useAddress";
import { ORDER } from "@/constants";
import { h, ref } from "vue";
export const useAdd = (options: any) => {
  const { tableRef } = options;
  const { promise, getDictId } = useDict(["orderType", "industry", "customerType", "scenario", "shippingMethod"]);
  const { countryList, areaList, defaultOptions, promise: addressPromise } = useAddress(); // defaultOptions, areaList

  const config = ref({});
  const listAllUser = ref<any>([]);
  const dictList = ref<any>([]);
  const companyList = ref<any>([]);
  const getProjectListCodeAllList = ref<any>([]);
  const openDialog = async () => {
    await getDataInit();
    config.value = {
      title: "新增订单审核",
      width: 80,
      height: "80vh",
      form: {
        formData: {
          name: undefined,
          code: undefined,
          linkOrderId: undefined,
          orderTypeId: undefined,
          companyId: undefined,
          companyName: undefined,
          companyFinalId: undefined,
          companyFinalName: undefined,
          businessId: undefined,
          orderTime: undefined,
          deliveryTypeId: undefined,
          deliveryLocation: undefined,
          mechanicalDesignNumber: undefined,
          // planPurchaseTime: undefined,
          // planMechanicalDesignTime: undefined,
          // planBomTime: undefined,
          // planElectricalSchematicsTime: undefined,
          // planWiringDiagramTime: undefined,
          // planProductionCompletedTime: undefined,
          // planCustomSoftwareDevelopmentTime: undefined,
          // planDebugCompletedTime: undefined,
          planDeliveryTime: undefined,
          purchaseTime: undefined,
          mechanicalDesignTime: undefined,
          bomTime: undefined,
          electricalSchematicsTime: undefined,
          wiringDiagramTime: undefined,
          productionCompletedTime: undefined,
          customSoftwareDevelopmentTime: undefined,
          debugCompletedTime: undefined,
          deliveryTime: undefined,
          purchaseDelay: undefined,
          purchaseDelayTime: undefined,
          mechanicalDesignDelay: undefined,
          mechanicalDesignDelayTime: undefined,
          bomDelay: undefined,
          bomDelayTime: undefined,
          electricalSchematicsDelay: undefined,
          electricalSchematicsDelayTime: undefined,
          wiringDiagramDelay: undefined,
          wiringDiagramDelayTime: undefined,
          productionCompletedDelay: undefined,
          productionCompletedDelayTime: undefined,
          customSoftwareDevelopmentDelay: undefined,
          customSoftwareDevelopmentDelayTime: undefined,
          debugCompletedDelay: undefined,
          debugCompletedDelayTime: undefined,
          deliveryDelay: undefined,
          deliveryDelayTime: undefined,
          orderDelay: undefined,
          orderDelayTime: undefined,
          contractCode: undefined,
          contractSignTime: undefined,
          saleUserId: undefined,
          saleUserName: undefined,
          jointUserId: undefined,
          jointUserName: undefined,
          planUserName: undefined,
          planUserId: undefined,
          stageId: undefined,
          // spContent: {},
          spStatus: undefined,
          orderStatus: undefined,
          productCategoryList: [],
          orderMaterielList: [],
          supportingHardware: [], // 自定义配套硬件
          softwareSystems: [], // 自定义软件系统
          construction: [], // 自定义施工
          serve: [], // 自定义服务
          // other: [], // 自定义其他
          delayTime: undefined,
          province: undefined,
          city: undefined,
          industryId: undefined,
          // addressed: [], // 自定义国内省市区
          sceneId: undefined,
          projectFilesList: [],
          orderConfirmationForm: [], // 自定义订单确认表
          technicalAgreements: [], // 自定义技术协议
          planningScheme: [], // 自定义规划方案
          layoutDrawing: [], // 自定义布局图
          projectUserList: undefined,
          orderFollowModel: undefined,
          projectId: undefined,
          projectCode: undefined,
          projectName: undefined,
          userId: undefined,
          userName: undefined,
          avatarUrl: undefined,
          description: undefined,
          projectTypeId: undefined,
          countryId: "1790268896943538176",
          countryName: "中国",
          provinceCode: undefined,
          cityCode: undefined,
          district: undefined,
          districtCode: undefined,
          address: undefined,
          hardwareNonStandardId: undefined,
          hardwareContent: undefined,
          hardwareCycle: undefined,
          softwareNonStandardId: undefined,
          softwareContent: undefined,
          softwareCycle: undefined,
          agvCount: undefined,
          progress: undefined,
          progressId: undefined,
          projectStatus: undefined,
          statusDescription: undefined,
          projectPlanStartTime: undefined,
          projectPlanEndTime: undefined,
          projecrStartTime: undefined,
          projecrEndTime: undefined
        },
        rules: {
          name: [{ required: true, message: "请填写名称" }],
          typeId: [{ required: true, message: "请选择订单类型" }],
          contractCode: [{ required: true, message: "请填写合同编号" }],
          saleUserId: [{ required: true, message: "请选择销售人员" }],
          code: [{ required: true, message: "请填写订单编号" }],
          deliveryLocation: [{ required: true, message: "请填写交货地点" }],
          companyId: [{ required: true, message: "请选择" }],
          companyFinalId: [{ required: true, message: "请选择" }],
          planDeliveryTime: [{ required: true, message: "请选择" }],
          orderConfirmationForm: [{ required: true, message: "请选择" }],
          technicalAgreements: [{ required: true, message: "请选择" }],
          productCategoryList: [{ required: true, message: "必须添加一个车辆", trigger: "change" }],
          countryId: [{ required: true, message: "请选择" }],
          addressed: [{ required: true, message: "请选择" }],
          city: [{ required: true, message: "请填写" }],
          industryId: [{ required: true, message: "请选择" }],
          sceneId: [{ required: true, message: "请选择" }],
          deliveryTypeId: [{ required: true, message: "请选择" }],
          orderTime: [{ required: true, message: "请选择" }],
          planUserId: [{ required: true, message: "请选择" }],
          contractSignTime: [{ required: true, message: "请选择" }],
          // planPurchaseTime: [{ required: true, message: "请选择" }],
          // planMechanicalDesignTime: [{ required: true, message: "请选择" }],
          // planBomTime: [{ required: true, message: "请选择" }],
          // planElectricalSchematicsTime: [{ required: true, message: "请选择" }],
          // planWiringDiagramTime: [{ required: true, message: "请选择" }],
          // planProductionCompletedTime: [{ required: true, message: "请选择" }],
          // planCustomSoftwareDevelopmentTime: [{ required: false, message: "请选择" }],
          // planDebugCompletedTime: [{ required: false, message: "请选择" }],
          dynamicWrite: [
            { required: true, message: "请填写" },
            {
              validator: (rule: any, value: any, callback: any) => {
                console.log(rule);
                if (value <= 0) {
                  callback(new Error("必须大于0"));
                } else {
                  callback();
                }
              },
              trigger: "blur"
            }
          ],
          dynamicSelect: [
            {
              required: true,
              message: "请选择"
            }
          ]

          // typeId: [{ required: true, message: "请选择问题类型" }],
          // title: [{ required: true, message: "请填写问题标题" }],
          // content: [{ required: true, message: "请填写问题内容" }],
          // questionImg: [{ required: true, message: "请上传问题图片" }]
        },
        attribute: {
          "label-suffix": ""
        }
      },
      api: addOrder,
      column: [
        {
          type: "group",
          title: "基本信息",
          direction: "",
          len: 4,
          layout: "grid",
          list: [
            {
              type: "input",
              key: "name",
              formItemAttribute: {
                label: "名称"
              },
              attributes: {
                placeholder: "请填写"
              }
            },
            {
              type: "select",
              key: "typeId",
              formItemAttribute: {
                label: "订单类型"
              },
              attributes: {
                placeholder: "请选择",
                options: dictList.value[getDictId("orderType")],
                multiple: false,
                filterable: true,
                clearable: true
              }
            },
            {
              type: "input",
              key: "code",
              formItemAttribute: {
                label: "订单编号"
              },
              attributes: {
                placeholder: "请填写",
                options: [],
                multiple: false,
                filterable: true,
                clearable: true
              }
            },
            {
              type: "select",
              key: "linkOrderId",

              formItemAttribute: {
                label: "关联订单编号"
              },
              attributes: {
                placeholder: "请选择",
                options: getProjectListCodeAllList.value,
                multiple: false,
                filterable: true,
                clearable: true
              },
              fieldNames: {
                label: "nameClone",
                value: "id"
              }
            },
            {
              type: "select",
              key: "companyId",
              formItemAttribute: {
                label: "直接客户"
              },
              attributes: {
                placeholder: "请选择",
                options: companyList.value,
                multiple: false,
                filterable: true,
                clearable: true,
                changeFn: (val: any, originConfig: any) => {
                  const country = companyList.value.find((item: any) => item.id === val);
                  originConfig.formData.companyName = country?.name;
                }
              }
            },
            {
              type: "select",
              key: "companyFinalId",
              formItemAttribute: {
                label: "终端客户"
              },
              attributes: {
                placeholder: "请选择",
                options: companyList.value,
                multiple: false,
                filterable: true,
                clearable: true,
                changeFn: (val: any, originConfig: any) => {
                  const country = companyList.value.find((item: any) => item.id === val);
                  originConfig.formData.companyFinalName = country?.name;
                }
              }
            },
            {
              type: "select",
              key: "countryId",
              formItemAttribute: {
                label: "应用国家"
              },
              attributes: {
                placeholder: "请选择",
                options: countryList,
                multiple: false,
                filterable: true,
                clearable: true,
                changeFn: (val: any, originConfig: any, configModel: any) => {
                  const country = countryList.value.find((item: any) => item.id === val);
                  originConfig.formData.countryName = country?.countryName;
                  originConfig.formData.addressed = [];
                  originConfig.formData.province = "";
                  originConfig.formData.city = "";
                  originConfig.formData.district = "";
                  originConfig.formData.provinceCode = "";
                  originConfig.formData.cityCode = "";
                  originConfig.formData.districtCode = "";
                  if (country && country.countryName === "中国") {
                    configModel.column[0].list.forEach((itm: any) => {
                      if (itm.key === "addressed") {
                        itm.attributes.disabled = false;
                        itm.isHidden = false;
                      }
                      if (itm.key === "city") {
                        itm.isHidden = true;
                      }
                    });
                  } else {
                    configModel.column[0].list.forEach((itm: any) => {
                      if (itm.key === "addressed") {
                        itm.attributes.disabled = true;
                        itm.isHidden = true;
                      }
                      if (itm.key === "city") {
                        itm.isHidden = false;
                      }
                    });
                  }
                }
              },
              fieldNames: {
                label: "countryName",
                value: "id"
              }
            },
            {
              type: "cascader",
              key: "addressed",
              formItemAttribute: {
                label: "应用城市"
              },
              attributes: {
                placeholder: "请选择",
                ref: "cascaderRef",
                options: areaList,
                clearable: true,
                disabled: false,
                props: defaultOptions.value,
                changeFn: (val: any, originConfig: any, configModel: any, cascaderRef: any) => {
                  let arrAddress = cascaderRef.getCheckedNodes();
                  let names = arrAddress[0]["pathLabels"];
                  originConfig.formData.province = names[0];
                  originConfig.formData.city = names[1];
                  originConfig.formData.district = names[2];
                  originConfig.formData.provinceCode = val[0];
                  originConfig.formData.cityCode = val[1];
                  originConfig.formData.districtCode = val[2];
                }
              },

              isHidden: false
            },
            {
              type: "input",
              key: "city",
              formItemAttribute: {
                label: "应用城市"
              },
              attributes: {
                placeholder: "请填写",
                clearable: true
              },

              isHidden: true
            },

            // {
            //   type: "select",
            //   key: "province",
            //   formItemAttribute: {
            //     label: "应用省份"
            //   },
            //   attributes: {
            //     placeholder: "请选择",
            //     options: [],
            //     multiple: false,
            //     filterable: true,
            //     clearable: true
            //   }
            // },
            // {
            //   type: "select",
            //   key: "city",
            //   formItemAttribute: {
            //     label: "应用城市"
            //   },
            //   attributes: {
            //     placeholder: "请选择",
            //     options: [],
            //     multiple: false,
            //     filterable: true,
            //     clearable: true
            //   }
            // },
            {
              type: "select",
              key: "industryId",
              formItemAttribute: {
                label: "应用行业"
              },
              attributes: {
                placeholder: "请选择",
                options: dictList.value[getDictId("industry")],
                multiple: false,
                filterable: true,
                clearable: true
              }
            },
            {
              type: "select",
              key: "sceneId",
              formItemAttribute: {
                label: "应用场景"
              },
              attributes: {
                placeholder: "请选择",
                options: dictList.value[getDictId("scenario")],
                multiple: false,
                filterable: true,
                clearable: true
              }
            },
            {
              type: "select",
              key: "deliveryTypeId",
              formItemAttribute: {
                label: "发货方式"
              },
              attributes: {
                placeholder: "请选择",
                options: dictList.value[getDictId("shippingMethod")],
                multiple: false,
                filterable: true,
                clearable: true
              }
            },
            {
              type: "input",
              key: "contractCode",
              formItemAttribute: {
                label: "合同编号"
              },
              attributes: {
                placeholder: "请填写",
                clearable: true
              }
            },
            {
              type: "date-picker",
              key: "contractSignTime",
              formItemAttribute: {
                label: "合同签订日期"
              },
              attributes: {
                type: "date",
                placeholder: "请选择",
                format: "YYYY-MM-DD",
                valueFormat: "YYYY-MM-DD HH:mm:ss"
              }
            },
            {
              type: "date-picker",
              key: "planDeliveryTime",
              formItemAttribute: {
                label: "发货日期"
              },
              attributes: {
                type: "date",
                placeholder: "请选择",
                format: "YYYY-MM-DD",
                valueFormat: "YYYY-MM-DD HH:mm:ss"
              }
            },
            {
              type: "input",
              key: "deliveryLocation",
              formItemAttribute: {
                label: "交货地点"
              },
              attributes: {
                placeholder: "请填写"
              }
            },
            {
              type: "date-picker",
              key: "orderTime",
              formItemAttribute: {
                label: "下单日期"
              },
              attributes: {
                type: "date",
                placeholder: "请选择",
                format: "YYYY-MM-DD",
                valueFormat: "YYYY-MM-DD HH:mm:ss"
              }
            },
            {
              type: "select",
              key: "saleUserId",
              formItemAttribute: {
                label: "销售"
              },
              attributes: {
                placeholder: "请选择",
                options: listAllUser.value,
                multiple: false,
                filterable: true,
                clearable: true,
                changeFn: (val: any, originConfig: any) => {
                  const country = listAllUser.value.find((item: any) => item.id === val);
                  originConfig.formData.saleUserName = country?.name;
                }
              }
            },
            {
              type: "select",
              key: "planUserId",
              formItemAttribute: {
                label: "规划设计"
              },
              attributes: {
                placeholder: "请选择",
                options: listAllUser.value,
                multiple: false,
                filterable: true,
                clearable: true,
                changeFn: (val: any, originConfig: any) => {
                  const country = listAllUser.value.find((item: any) => item.id === val);
                  originConfig.formData.planUserName = country?.name;
                }
              }
            }
          ]
        },
        {
          type: "input",
          key: "remark",
          formItemAttribute: {
            label: "备注"
          },
          attributes: {
            placeholder: "请填写"
          }
        },
        // {
        //   type: "group",
        //   title: "订单计划",
        //   direction: "",
        //   len: 4,
        //   layout: "grid",
        //   list: [
        //     {
        //       type: "date-picker",
        //       key: "planPurchaseTime",
        //       formItemAttribute: {
        //         label: "预采清单下发"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planMechanicalDesignTime",
        //       formItemAttribute: {
        //         label: "机械图纸下发"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planBomTime",
        //       formItemAttribute: {
        //         label: "BOM下发"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planElectricalSchematicsTime",
        //       formItemAttribute: {
        //         label: "电气原理图"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planWiringDiagramTime",
        //       formItemAttribute: {
        //         label: "线束图下发"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planProductionCompletedTime",
        //       formItemAttribute: {
        //         label: "制造完成入库"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planCustomSoftwareDevelopmentTime",
        //       formItemAttribute: {
        //         label: "定制开发（可选）"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     },
        //     {
        //       type: "date-picker",
        //       key: "planDebugCompletedTime",
        //       formItemAttribute: {
        //         label: "调试完成（可选）"
        //       },
        //       attributes: {
        //         type: "date",
        //         placeholder: "请选择",
        //         format: "YYYY-MM-DD",
        //         valueFormat: "YYYY-MM-DD HH:mm:ss"
        //       }
        //     }
        //   ]
        // },
        {
          type: "group",
          title: "合同标的",
          direction: "",
          len: 1,
          layout: "grid",
          list: [
            {
              type: "slot",
              key: "productCategoryList",
              formItemAttribute: {
                label: "整机"
              },
              attributes: {
                placeholder: "请填写"
              }
            },
            {
              type: "slot",
              key: "supportingHardware",
              formItemAttribute: {
                label: "配套硬件"
              },
              attributes: {
                placeholder: "请填写"
              }
            },
            {
              type: "slot",
              key: "softwareSystems",
              formItemAttribute: {
                label: "软件系统"
              },
              attributes: {
                placeholder: "请填写"
              }
            },
            {
              type: "slot",
              key: "construction",
              formItemAttribute: {
                label: "施工"
              },
              attributes: {
                placeholder: "请填写"
              }
            },
            {
              type: "slot",
              key: "serve",
              formItemAttribute: {
                label: "服务"
              },
              attributes: {
                placeholder: "请填写"
              }
            }
            // {
            //   type: "slot",
            //   key: "other",
            //   formItemAttribute: {
            //     label: "其他"
            //   },
            //   attributes: {
            //     placeholder: "请填写"
            //   }
            // }
          ]
        },
        // {
        //   type: "group",
        //   title: "审批流程",
        //   direction: "",
        //   len: 4,
        //   layout: "grid",
        //   list: [
        //     {
        //       type: "select",
        //       key: "stageId",
        //       formItemAttribute: {
        //         label: "审批流选择"
        //       },
        //       attributes: {
        //         placeholder: "请选择",
        //         options: [],
        //         multiple: false,
        //         filterable: true,
        //         clearable: true
        //       }
        //     }
        //   ]
        // },
        {
          type: "group",
          title: "订单资料",
          direction: "",
          len: 4,
          layout: "grid",
          list: [
            {
              type: "fileSlice",
              key: "orderConfirmationForm",
              formItemAttribute: {
                label: "订单确认表"
              },
              attributes: {
                "prefix-data": ORDER,
                "limit-number": 100,
                "size-limit": 1024 * 1024 * 15,
                accept: "*",
                success: (data: any) => {
                  console.log(data);
                }
              }
            },
            {
              type: "fileSlice",
              key: "technicalAgreements",
              formItemAttribute: {
                label: "技术协议"
              },
              attributes: {
                "prefix-data": ORDER,
                "limit-number": 100,
                "size-limit": 1024 * 1024 * 15,
                accept: "*",
                success: (data: any) => {
                  console.log(data);
                }
              }
            },
            {
              type: "fileSlice",
              key: "planningScheme",
              formItemAttribute: {
                label: "规划方案（选填）"
              },
              attributes: {
                "prefix-data": ORDER,
                "limit-number": 100,
                "size-limit": 1024 * 1024 * 15,
                accept: "*",
                success: (data: any) => {
                  console.log(data);
                }
              }
            },
            {
              type: "fileSlice",
              key: "layoutDrawing",
              formItemAttribute: {
                label: "布局图（选填）"
              },
              attributes: {
                "prefix-data": ORDER,
                "limit-number": 100,
                "size-limit": 1024 * 1024 * 15,
                accept: "*",
                success: (data: any) => {
                  console.log(data);
                }
              }
            }
          ]
        }
      ],
      transformData: (data: any) => {
        // 处理地址
        delete data.addressed;
        // 处理文件
        // orderConfirmationForm: [], // 自定义订单确认表
        // technicalAgreements: [], // 自定义技术协议
        // planningScheme: [], // 自定义规划方案
        // layoutDrawing: [], // 自定义布局图
        data.orderConfirmationForm.forEach((item: any) => {
          data.projectFilesList.push({
            typeId: getDictId("projectOrderConfirmationForm"),
            name: item.originalFileName,
            path: item.path,
            originalFileName: item.originalFileName
          });
        });
        data.technicalAgreements.forEach((item: any) => {
          data.projectFilesList.push({
            typeId: getDictId("technicalAgreements"),
            name: item.originalFileName,
            path: item.path,
            originalFileName: item.originalFileName
          });
        });
        data.planningScheme.forEach((item: any) => {
          data.projectFilesList.push({
            typeId: getDictId("planYourScenario"),
            name: item.originalFileName,
            path: item.path,
            originalFileName: item.originalFileName
          });
        });
        data.layoutDrawing.forEach((item: any) => {
          data.projectFilesList.push({
            typeId: getDictId("bomList"),
            name: item.originalFileName,
            path: item.path,
            originalFileName: item.originalFileName
          });
        });
        delete data.orderConfirmationForm;
        delete data.technicalAgreements;
        delete data.planningScheme;
        delete data.layoutDrawing;
        // 处理整车
        data.productCategoryList = data.productCategoryList.map((item: any) => {
          delete item.uuid;
          return item;
        });
        // 处理物料
        // orderMaterielList: [],
        // supportingHardware: [], // 自定义配套硬件
        // softwareSystems: [], // 自定义软件系统
        // construction: [], // 自定义施工
        // serve: [], // 自定义服务
        data.orderMaterielList = [...data.supportingHardware, ...data.softwareSystems, ...data.construction, ...data.serve];
        delete data.supportingHardware;
        delete data.softwareSystems;
        delete data.construction;
        delete data.serve;
        data.orderMaterielList = data.orderMaterielList.map((item: any) => {
          delete item.uuid;
          return item;
        });
        return data;
      },
      message: "订单创建成功"
    };

    const options: DialogFormOptions = {
      config: config.value,
      closeCallback: () => {},
      slots: {
        productCategoryList: (props: any) => {
          return h(AgvTypeEdit, {
            list: props.scope["productCategoryList"],
            keysName: "productCategoryList",
            rules: config.value["form"].rules
          });
        },
        supportingHardware: (props: any) => {
          return h(ContractEdit, {
            list: props.scope["supportingHardware"],
            typeId: getDictId("supportingHardware"),
            rules: config.value["form"].rules,
            keysName: "supportingHardware"
          });
        },
        softwareSystems: (props: any) => {
          return h(ContractEdit, {
            list: props.scope["softwareSystems"],
            typeId: getDictId("softwareSystems"),
            rules: config.value["form"].rules,
            keysName: "softwareSystems"
          });
        },
        construction: (props: any) => {
          return h(ContractEdit, {
            list: props.scope["construction"],
            typeId: getDictId("construction"),
            rules: config.value["form"].rules,
            keysName: "construction"
          });
        },
        serve: (props: any) => {
          return h(ContractEdit, {
            list: props.scope["serve"],
            typeId: getDictId("serve"),
            rules: config.value["form"].rules,
            keysName: "serve"
          });
        }
        // other: (props: any) => {
        //   return h(ContractEdit, { list: props.scope["other"], typeId: getDictId("planYourScenario") });
        // }
      },
      successCallback: () => {
        tableRef.value.refresh();
      }
    };

    dialogForm(options);
  };
  // 获取全部用户
  const getListAllUserFn = async () => {
    const { data } = await getListAllUser();
    listAllUser.value = data;
  };
  // 获取全部公司
  const getCompanyListFn = async () => {
    const { data } = await getCompanyList();
    companyList.value = data || [];
  };

  // 查询全部项目编号和项目名称（包含老项目）
  const getProjectCodeListFn = async () => {
    const { data } = await getProjectListCodeAll();
    getProjectListCodeAllList.value =
      (data &&
        data.map((item: any) => {
          item.nameClone = item.code + "-" + item.name;
          return item;
        })) ||
      [];
  };
  // 数据获取
  const getDataInit = async () => {
    await Promise.all([getListAllUserFn(), getCompanyListFn(), getProjectCodeListFn()]);
    dictList.value = await promise;
    await addressPromise;
  };
  return {
    openDialog
  };
};
